package com.link.base.base.trackchild.controller;
/**
 * @author: 秦学刚
 * @date: 2018-11-21
 * @comments:
 */

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.link.base.base.trackchild.model.Trackchild;
import com.link.base.base.trackchild.service.TrackchildService;
import com.link.core.cllog.LCLogger;
import com.link.core.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/link/trackchild")
public class TrackchildController extends BasicController<Trackchild> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private TrackchildService trackchildService;

    @Override
    public BasicService<Trackchild> getBasicService() throws Exception {
        return trackchildService;
    }

    /**
     * <p>更新redis中的URL信息</p>
     *
     * @param request
     * @return
     * @author 秦学刚
     */
    @RequestMapping(value = "/flushCache")
    @ResponseBody
    public Map<String, Object> updateRedisCache(HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            trackchildService.loadTrackToRedis();
            result.put("success", true);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    @Override
    public void beforUpsert(Trackchild entity, HttpServletRequest request) throws Exception {
        if (StringUtils.isBlank(entity.getDisplayValue())) {
            entity.setDisplayValue("");
        }
    }
}
